package nancal.mp.model

import nancal.mp.db.mongo.entity.dev.AppDeploySetting
import nancal.mp.db.mongo.extend.getAppDeploySetting
import nancal.mp.db.mongo.mor
import nbcp.base.annotation.Require


data class OpsDeployModel(
    @Require
    var gitId: String = "",

    /**
     * 就是 folder
     */
    @Require
    var name: String = "",
    var targetEnv: String = "", //目标 appDeploySettingCode
    var clusterCode: String = ""
) {

    val targetEnvDeploySetting: AppDeploySetting
        get() {
            return mor.dev.appDeploySetting.getAppDeploySetting(this.targetEnv)
        }


    @Require
    var gitBranch: String = ""
        get() {
            if (field.contains(",")) {
                return field.split(",").sortedBy { it.length }.first()
            }
            return field;
        }
        set(v) {
            if (v.contains(",")) {
                field = v.split(",").sortedBy { it.length }.first()
                return;
            }
            field = v
        }
}
